const personalCenter = {
  namespaced: true,

  state: {
    userInfo: {
      //用户登录信息
      tid: '',
      mobile: '',
      isRegist: false,
      infoDegree: 0,
      permious: '',
      role: '',
    },
    imei: '', //设备信息
    servicePhone: 4000909987, //客服电话
    isJoinCompany: false, //是否是加入公司
    companyName: '', //注册时的企业名称

    beginTime: '',
    endTime: '',
    isRefresh: false,

    registerInfo: {
      name: '',
      psd: ''
    }
  },

  mutations: {
    //存储用户信息
    setUserInfo(state, data) {
      state.userInfo.tid = data.tid
      state.userInfo.mobile = data.mobile
      state.userInfo.isRegist = data.isRegist
      state.userInfo.infoDegree = data.infoDegree
      state.userInfo.permious = data.permious ? data.permious : ''
			state.userInfo.merchant_type=data.merchant_type
			state.userInfo.examine_status=data.examine_status
      state.userInfo.role = data.role
    },
    //存储用户角色权限
    setUserRole(state, data) {
      state.userInfo.role = data
    },

    //存储设备imei
    setImei(state, data) {
      state.imei = data
      console.log('setImei')
    },

    //加入公司信息
    setCompanyInfo(state, data) {
      console.log('37--')
      state.companyName = data.name
      state.isJoinCompany = data.isJoinCompany
    },

    //资产管理查询时间
    setTime(state, data) {
      state.beginTime = data.beginTime
      state.endTime = data.endTime
      state.isRefresh = true
    },

    setIsRefresh(state, data) {
      state.isRefresh = data
    },

    //清空个人信息
    resetInfo(state) {
      state.userInfo.tid = ''
      state.userInfo.mobile = ''
      state.userInfo.isRegist = false
      state.userInfo.infoDegree = 0
      state.userInfo.permious = ''
      state.userInfo.role = ''
    },
    // 暂存企业名称
    setRegisterInfo(state, data) {
      state.registerInfo.name = data.name
      state.registerInfo.psd = data.psd
    }
  },

  actions: {
    //获取注册/加入公司信息
    getUserCompany({
      commit
    }, data) {
      return data._this.$api.user.getUserCompany().then(res => {
        if (res.data.name) {
          commit('setCompanyInfo', {
            name: res.data.name,
            isJoinCompany: !res.data.isNew,
          })
        }
      })
    },
  },
}

export default personalCenter
